package com.yfjin.ffmpeg52

import android.Manifest
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.view.Surface
import android.view.SurfaceHolder
import android.view.SurfaceView
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import java.io.File
import kotlin.concurrent.thread


class MainActivityVideo : AppCompatActivity(), SurfaceHolder.Callback {

    companion object {
        init {
            System.loadLibrary("video-native-lib")
        }
    }

    external fun stringFromJNI(): String
    external fun play(url: String, surface: Surface): Int

    private lateinit var mSurfaceView: SurfaceView
    private lateinit var mSurface:Surface
    private lateinit var mButton:View

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        mSurfaceView = findViewById(R.id.v_surface)
        mSurfaceView.holder.addCallback(this)

        mButton=findViewById(R.id.v_play)
        mButton.setOnClickListener {
            play();

        }
    }

    private fun play() {
        val folderurl = File(Environment.getExternalStorageDirectory(), "123.mp4").getAbsolutePath();
        thread {
            play(folderurl, mSurface)
        }
    }


    override fun surfaceCreated(holder: SurfaceHolder) {
        mSurface=holder.surface
    }

    override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
    }

    override fun surfaceDestroyed(holder: SurfaceHolder) {
    }

}